{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/data/ods\n"
     ]
    },
    {
     "ename": "UnboundLocalError",
     "evalue": "local variable 'files' referenced before assignment",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mUnboundLocalError\u001B[0m                         Traceback (most recent call last)",
      "Input \u001B[0;32mIn [35]\u001B[0m, in \u001B[0;36m<cell line: 10>\u001B[0;34m()\u001B[0m\n\u001B[1;32m      7\u001B[0m         \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mfiles:\u001B[39m\u001B[38;5;124m'\u001B[39m, files)     \u001B[38;5;66;03m#文件名称，返回list类型\u001B[39;00m\n\u001B[1;32m      8\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m files\n\u001B[0;32m---> 10\u001B[0m file_name \u001B[38;5;241m=\u001B[39m \u001B[43mgetFlist\u001B[49m\u001B[43m(\u001B[49m\u001B[43mfile_dir\u001B[49m\u001B[43m)\u001B[49m\n",
      "Input \u001B[0;32mIn [35]\u001B[0m, in \u001B[0;36mgetFlist\u001B[0;34m(path)\u001B[0m\n\u001B[1;32m      6\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m files \u001B[38;5;129;01min\u001B[39;00m os\u001B[38;5;241m.\u001B[39mwalk(path):\n\u001B[1;32m      7\u001B[0m     \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mfiles:\u001B[39m\u001B[38;5;124m'\u001B[39m, files)     \u001B[38;5;66;03m#文件名称，返回list类型\u001B[39;00m\n\u001B[0;32m----> 8\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mfiles\u001B[49m\n",
      "\u001B[0;31mUnboundLocalError\u001B[0m: local variable 'files' referenced before assignment"
     ]
    }
   ],
   "source": [
    "import os\n",
    "file_dir = '/data/ods'  #你的文件路径\n",
    "\n",
    "def getFlist(path):\n",
    "    print(path)\n",
    "    for files in os.walk(path):\n",
    "        print('files:', files)     #文件名称，返回list类型\n",
    "    return files\n",
    "\n",
    "file_name = getFlist(file_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json\n",
    "# import os\n",
    "#'dw_cpu2006_fprate.csv','dw_cpu2006_fpspeed.csv','dw_cpu2006_intrate.csv','dw_cpu2006_intspeed.csv','dw_cpu2017_fprate.csv','dw_cpu2017_fpspeed.csv','dw_cpu2017_intrate.csv','dw_cpu2017_intspeed.csv','dw_jvm2008.csv','dw_jbb2015_comp.csv','dw_jbb2015_dist.csv','dw_jbb2015_multi.csv','dw_power_ssj2008.csv'\n",
    "\n",
    "benchmark_list=['dw_cpu2006_fprate.csv','dw_cpu2006_fpspeed.csv','dw_cpu2006_intrate.csv','dw_cpu2006_intspeed.csv','dw_cpu2017_fprate.csv','dw_cpu2017_fpspeed.csv','dw_cpu2017_intrate.csv','dw_cpu2017_intspeed.csv','dw_jvm2008.csv','dw_jbb2015_comp.csv','dw_jbb2015_dist.csv','dw_jbb2015_multi.csv','dw_power_ssj2008.csv']\n",
    "jsons = {}\n",
    "for benchmark_name in benchmark_list:\n",
    "    #print(benchmark_name)\n",
    "    table_json = {}\n",
    "    data = pd.read_csv(\"data/dw/\"+benchmark_name)\n",
    "    i = 0\n",
    "    table_json['in_chinese'] = benchmark_name[:-4]\n",
    "    table_json['col_name'] = {\"Company\":\"Company\", \"System\": \"System\",\"Result\": \"Result\",\"# cores,Processor\": \"# cores,Processor\",\"CPU Speed(MHz)\": \"CPU Speed(MHz)\",\"1st Cache per core(KB)\": \"1st Cache per core(KB)\",\"2nd Cache per core(KB)\": \"2nd Cache per core(KB)\",\"3rd Cache per chip(MB)\": \"3rd Cache per chip(MB)m\",\"Other Cache per chip(MB)\":\"Other Cache per chip(MB)\",\"Memory(GB)\":\"Memory(GB)\",\"Updated\":\"Updated\",\"Report Link\":\"Report Link\"}\n",
    "    table_json['dtype_dict'] = {\"Company\":\"str\", \"System\": \"str\",\"Result\": \"str\",\"# cores,Processor\": \"str\",\"CPU Speed(MHz)\": \"str\",\"1st Cache per core(KB)\": \"str\",\"2nd Cache per core(KB)\": \"str\",\"3rd Cache per chip(MB)\": \"str\",\"Other Cache per chip(MB)\":\"str\",\"Memory(GB)\":\"str\",\"Updated\":\"str\",\"Report Link\":\"str\"}\n",
    "    table_json['desc'] = 'bench'\n",
    "\n",
    "    for column in data:\n",
    "        if column != 'Unnamed: 0':\n",
    "            #print(column)\n",
    "            df=data[column]\n",
    "            df = df.drop_duplicates()\n",
    "            df = df.dropna(axis=0, how='any')\n",
    "            #print(type(df))\n",
    "            row = {}\n",
    "            row_type = {}\n",
    "            for value in df.values:\n",
    "                # print(type(value))\n",
    "                row[str(value)] = str(value)\n",
    "                row_type[str(value)] = str(type(value))\n",
    "            table_json[column] = row\n",
    "            table_json['dtype_dict'] = row_type\n",
    "\n",
    "            # table_json['dtype_dict'] = {\"Company\":\"str\", \"System\": \"str\",\"Result\": \"int\",\"# cores,Processor\": \"int\",\"CPU Speed(MHz)\": \"int\",\"1st Cache per core(KB)\": \"str\",\"2nd Cache per core(KB)\": \"str\",\"3rd Cache per chip(MB)\": \"str\",\"Other Cache per chip(MB)\":\"str\",\"Memory(GB)\":\"int\",\"Updated\":\"str\",\"Report Link\":\"str\"}\n",
    "    jsons[benchmark_name[:-4]] = table_json\n",
    "# print(jsons)\n",
    "\n",
    "json_str = json.dumps(jsons, ensure_ascii=False, indent=4, separators=(',', ':'))\n",
    "# print(json_str)\n",
    "with open('dw_data.json', 'w') as f:\n",
    "    json.dump(json_str, f,ensure_ascii=False)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'get'",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mAttributeError\u001B[0m                            Traceback (most recent call last)",
      "Input \u001B[0;32mIn [67]\u001B[0m, in \u001B[0;36m<cell line: 6>\u001B[0;34m()\u001B[0m\n\u001B[1;32m      3\u001B[0m     Threshold \u001B[38;5;241m=\u001B[39m json\u001B[38;5;241m.\u001B[39mload(f)\n\u001B[1;32m      4\u001B[0m \u001B[38;5;66;03m#Threshold = eval(Threshold)\u001B[39;00m\n\u001B[1;32m      5\u001B[0m \u001B[38;5;66;03m#print(Threshold)\u001B[39;00m\n\u001B[0;32m----> 6\u001B[0m \u001B[43mThreshold\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget\u001B[49m(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mtext\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "\u001B[0;31mAttributeError\u001B[0m: 'str' object has no attribute 'get'"
     ]
    }
   ],
   "source": [
    "Threshold = []\n",
    "with open(\"threshold_pod_human.json\") as f: #,encoding='gb2312'\n",
    "    Threshold = json.load(f)\n",
    "#Threshold = eval(Threshold)\n",
    "#print(Threshold)\n",
    "Threshold.get('text')\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Company\n",
      "0                         Apple Inc.\n",
      "3    Huawei Technologies Corporation\n",
      "4                 Oracle Corporation\n",
      "7                              Sugon\n",
      "8              Sun Microsystems Inc.\n",
      "Name: Company, dtype: object\n",
      "********\n",
      "System\n",
      "0                        iMac (Early 2009)\n",
      "3                                  RH 2285\n",
      "4                         Netra SPARC T4-2\n",
      "5                               SPARC T3-2\n",
      "6                               SPARC T4-2\n",
      "7    Sugon I620-G20(Intel Xeon E5-2660 v3)\n",
      "8                          Sun Blade X6270\n",
      "9                           Sun Fire X4450\n",
      "Name: System, dtype: object\n",
      "********\n",
      "Result\n",
      "0      26.4\n",
      "1      37.4\n",
      "2      51.6\n",
      "3     336.0\n",
      "4     455.0\n",
      "5     321.0\n",
      "6     454.0\n",
      "7     853.0\n",
      "8     317.0\n",
      "9     284.0\n",
      "10    260.0\n",
      "Name: Result, dtype: float64\n",
      "********\n",
      "# cores\n",
      "0     2\n",
      "3    12\n",
      "4    16\n",
      "5    32\n",
      "7    20\n",
      "8     8\n",
      "9    24\n",
      "Name: # cores, dtype: int64\n",
      "********\n",
      "Processor\n",
      "0     Intel Core 2 Duo CPU E8335\n",
      "3               Intel Xeon E5645\n",
      "4                       SPARC T4\n",
      "5                       SPARC T3\n",
      "7          Intel Xeon E5-2660 v3\n",
      "8               Intel Xeon X5570\n",
      "9               Intel Xeon X7460\n",
      "10              Intel Xeon X7350\n",
      "Name: Processor, dtype: object\n",
      "********\n",
      "CPU Speed(MHz)\n",
      "0     2930\n",
      "3     2400\n",
      "4     2848\n",
      "5     1650\n",
      "7     2600\n",
      "9     2667\n",
      "10    2933\n",
      "Name: CPU Speed(MHz), dtype: int64\n",
      "********\n",
      "1st Cache per core(KB)\n",
      "0    32KB(I)+32KB(D)\n",
      "4    16KB(I)+16KB(D)\n",
      "5     16KB(I)+8KB(D)\n",
      "7          32KB(I+D)\n",
      "Name: 1st Cache per core(KB), dtype: object\n",
      "********\n",
      "2nd Cache per core(KB)\n",
      "0     3072KB\n",
      "3      256KB\n",
      "4      128KB\n",
      "5      384KB\n",
      "9     1536KB\n",
      "10    2048KB\n",
      "Name: 2nd Cache per core(KB), dtype: object\n",
      "********\n",
      "3rd Cache per chip(MB)\n",
      "0      0\n",
      "8    8MB\n",
      "Name: 3rd Cache per chip(MB), dtype: object\n",
      "********\n",
      "Other Cache per chip(MB)\n",
      "0       0\n",
      "3    12MB\n",
      "4     4MB\n",
      "7    25MB\n",
      "Name: Other Cache per chip(MB), dtype: object\n",
      "********\n",
      "Memory(GB)\n",
      "0      4GB\n",
      "3     48GB\n",
      "4    256GB\n",
      "9     64GB\n",
      "Name: Memory(GB), dtype: object\n",
      "********\n",
      "Updated\n",
      "0     Nov-2009\n",
      "3     Jan-2012\n",
      "5     Oct-2010\n",
      "6     Nov-2011\n",
      "7     Feb-2015\n",
      "8     Jun-2009\n",
      "9     Sep-2008\n",
      "10    Jul-2008\n",
      "Name: Updated, dtype: object\n",
      "********\n",
      "Report Link\n",
      "0     https://www.spec.org/jvm2008/results/res2009q4...\n",
      "1     https://www.spec.org/jvm2008/results/res2009q4...\n",
      "2     https://www.spec.org/jvm2008/results/res2009q4...\n",
      "3     https://www.spec.org/jvm2008/results/res2012q1...\n",
      "4     https://www.spec.org/jvm2008/results/res2012q1...\n",
      "5     https://www.spec.org/jvm2008/results/res2010q4...\n",
      "6     https://www.spec.org/jvm2008/results/res2011q4...\n",
      "7     https://www.spec.org/jvm2008/results/res2015q1...\n",
      "8     https://www.spec.org/jvm2008/results/res2009q2...\n",
      "9     https://www.spec.org/jvm2008/results/res2008q3...\n",
      "10    https://www.spec.org/jvm2008/results/res2008q3...\n",
      "Name: Report Link, dtype: object\n",
      "********\n"
     ]
    }
   ],
   "source": [
    "#输出hello\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "1",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mKeyError\u001B[0m                                  Traceback (most recent call last)",
      "File \u001B[0;32m~/miniconda3/envs/dataplatfrom/lib/python3.9/site-packages/pandas/core/indexes/base.py:3621\u001B[0m, in \u001B[0;36mIndex.get_loc\u001B[0;34m(self, key, method, tolerance)\u001B[0m\n\u001B[1;32m   3620\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m-> 3621\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_engine\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_loc\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcasted_key\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m   3622\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m err:\n",
      "File \u001B[0;32mpandas/_libs/index.pyx:136\u001B[0m, in \u001B[0;36mpandas._libs.index.IndexEngine.get_loc\u001B[0;34m()\u001B[0m\n",
      "File \u001B[0;32mpandas/_libs/index.pyx:163\u001B[0m, in \u001B[0;36mpandas._libs.index.IndexEngine.get_loc\u001B[0;34m()\u001B[0m\n",
      "File \u001B[0;32mpandas/_libs/hashtable_class_helper.pxi:5198\u001B[0m, in \u001B[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001B[0;34m()\u001B[0m\n",
      "File \u001B[0;32mpandas/_libs/hashtable_class_helper.pxi:5206\u001B[0m, in \u001B[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001B[0;34m()\u001B[0m\n",
      "\u001B[0;31mKeyError\u001B[0m: 1",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001B[0;31mKeyError\u001B[0m                                  Traceback (most recent call last)",
      "Input \u001B[0;32mIn [3]\u001B[0m, in \u001B[0;36m<cell line: 1>\u001B[0;34m()\u001B[0m\n\u001B[1;32m      1\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m i \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mrange\u001B[39m(\u001B[38;5;241m1\u001B[39m,\u001B[38;5;241m14\u001B[39m):\n\u001B[0;32m----> 2\u001B[0m     col_name\u001B[38;5;241m=\u001B[39m\u001B[43mjvm\u001B[49m\u001B[43m[\u001B[49m\u001B[43mi\u001B[49m\u001B[43m]\u001B[49m\n\u001B[1;32m      3\u001B[0m     col_name\n",
      "File \u001B[0;32m~/miniconda3/envs/dataplatfrom/lib/python3.9/site-packages/pandas/core/frame.py:3505\u001B[0m, in \u001B[0;36mDataFrame.__getitem__\u001B[0;34m(self, key)\u001B[0m\n\u001B[1;32m   3503\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcolumns\u001B[38;5;241m.\u001B[39mnlevels \u001B[38;5;241m>\u001B[39m \u001B[38;5;241m1\u001B[39m:\n\u001B[1;32m   3504\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_getitem_multilevel(key)\n\u001B[0;32m-> 3505\u001B[0m indexer \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcolumns\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_loc\u001B[49m\u001B[43m(\u001B[49m\u001B[43mkey\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m   3506\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m is_integer(indexer):\n\u001B[1;32m   3507\u001B[0m     indexer \u001B[38;5;241m=\u001B[39m [indexer]\n",
      "File \u001B[0;32m~/miniconda3/envs/dataplatfrom/lib/python3.9/site-packages/pandas/core/indexes/base.py:3623\u001B[0m, in \u001B[0;36mIndex.get_loc\u001B[0;34m(self, key, method, tolerance)\u001B[0m\n\u001B[1;32m   3621\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_engine\u001B[38;5;241m.\u001B[39mget_loc(casted_key)\n\u001B[1;32m   3622\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m err:\n\u001B[0;32m-> 3623\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m(key) \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01merr\u001B[39;00m\n\u001B[1;32m   3624\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mTypeError\u001B[39;00m:\n\u001B[1;32m   3625\u001B[0m     \u001B[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001B[39;00m\n\u001B[1;32m   3626\u001B[0m     \u001B[38;5;66;03m#  InvalidIndexError. Otherwise we fall through and re-raise\u001B[39;00m\n\u001B[1;32m   3627\u001B[0m     \u001B[38;5;66;03m#  the TypeError.\u001B[39;00m\n\u001B[1;32m   3628\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_check_indexing_error(key)\n",
      "\u001B[0;31mKeyError\u001B[0m: 1"
     ]
    }
   ],
   "source": [
    "for i in range(1,14):\n",
    "    col_name=jvm[i]\n",
    "    col_name"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data1 = {'a': [1, 2, 3], 'b': [3, 4, 5], 'c': [5, 6, 7]}----type(data1) = <class 'dict'>\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": "   a  b  c test\n0  1  3  5  123\n1  2  4  6  123\n2  3  5  7  123",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n      <th>test</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>3</td>\n      <td>5</td>\n      <td>123</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>4</td>\n      <td>6</td>\n      <td>123</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>5</td>\n      <td>7</td>\n      <td>123</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data1 = {'a': [1, 2, 3],\n",
    "         'b': [3, 4, 5],\n",
    "         'c': [5, 6, 7]}\n",
    "\n",
    "print(\"data1 = {0}----type(data1) = {1}\".format(data1, type(data1)))\n",
    "print(\"-\" * 50)\n",
    "df1 = pd.DataFrame(data1)\n",
    "df2 = pd.DataFrame(data1)\n",
    "bench=\"123\"\n",
    "df1.insert(0, 'test', bench)\n",
    "# print(df1)\n",
    "\n",
    "df1"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}